<?php
/**
 * RabbitCMS
 * @author TrongHM
 * @since		1.0
 */

class Core_View_Helper_UserSelect
{
	const EOL = "\n";
	
	/**
	 * Display select box listing all categories
	 * 
	 * @param $attributes array
	 * @param string $lang
	 * @return string
	 */
      //add $module by tronghm
	public function userSelect($attributes = array())
	{
		
		
		$userModel = Rabbit_Model_Factory::getInstance()->setModule('core')->getUserModel();
		$users = $userModel->getAllUsers();
		
		$selectedId = isset($attributes['selected']) ? $attributes['selected'] : null;
		//$disableId  = isset($attributes['disable']) ? $attributes['disable'] : null;
		
		$output = sprintf("<select name='%s' id='%s' >", $attributes['name'], $attributes['id']) . self::EOL
				. '<option value="">---</option>' . self::EOL;

		if($users){
                foreach ($users as $user) {
                      $selected = ($selectedId == null || $selectedId != $user->id) ? '' : ' selected="selected"';
                      
                      $output  .= sprintf('<option value="%s"%s>%s</option>', $user->id, $selected, $user->username) . self::EOL;
                }
            }
		$output .= '</select>' . self::EOL;

		return $output;
	}
}
